<template>
	<view>
		<!--图标入口-->
		<view class="diy-navbar" :style="{background:itemData.style.background}">
			<view class="item" v-for="(item, index) in itemData.data" :key="index" :style="'width:'+item_width+';'" @click="gotoDetail(item)">
				<image :src="item.imgUrl" mode="widthFix"></image>
				<text class="gray3" :style="{color:item.color}">{{item.text}}</text>
			</view>
			<!--
			<view class="item" :style="'width:'+item_width+';'" @click="gotoDetail({linkUrl:'/pages/index/agent_agreement/agent_agreement'})">
				<image src="../../../static/icon/activity.png" mode="widthFix"></image>
				<text class="gray3">开通经销商</text>
			</view>
			<view class="item" :style="'width:'+item_width+';'" @click="gotoDetail({linkUrl:'/pages/product/category'})">
				<image src="../../../static/tabbar/category_0.png" mode="widthFix"></image>
				<text class="gray3">全部分类</text>
			</view>
			-->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//单个宽度
				item_width: '25%',
				detail:{},
				agent:{}
			}
		},
		props: ['itemData'],
		created() {
			this.item_width = 100 / Math.abs(this.itemData.style.rowsNum) + '%';
			let token = uni.getStorageSync('token')
			if(token){
				this.getUserInfo();
			}
		},
		methods: {
			/*获取数据*/
			getUserInfo() {
				let self = this;
				self.isloadding = true;
				self._get('user.index/detail', {
				}, function(res) {
					self.agent = res.data.agent;
					self.detail = res.data.userInfo;
					self.isloadding = false;
				});
			},
			
			/*跳转页面*/
			gotoDetail(e) {
				console.info(e)
				let userGradeId = this.detail.grade_id;
				console.info('用户等级ID',userGradeId)
				if(userGradeId && userGradeId>1 && (e.linkUrl == 'pages/index/agentupgrade' || e.name=='pages/index/agentupgrade')){
					this.showSuccess('您已经是会员了！');
					return false;
				}
				if(userGradeId && userGradeId==1 && (e.linkUrl == 'pages/index/agentproduct?category_id=63' || e.name=='pages/index/agentproduct?category_id=63')){
					this.showSuccess('您还不是会员！');
					return false;
				}
				/*
				if(userGradeId && userGradeId>2 && (e.linkUrl == 'pages/index/agentproduct?category_id=63' || e.name=='pages/index/agentproduct?category_id=63')){
					this.showSuccess('您已经是经销商了！');
					return false;
				}
				*/
				if(e.linkUrl){
					this.gotoPage(e.linkUrl);
				}else{
					this.gotoPage(e.name);
				}
				
			}
		}
	}
</script>

<style>
	.diy-navbar {
		margin: 20rpx;
		padding: 20rpx 0;
		border-radius: 6rpx;
		background: #FFFFFF;
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
	}

	.diy-navbar .item {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 20rpx;
		width: 120rpx;
		height: 140rpx;
	}

	.diy-navbar .item image {
		width: 70rpx;
		height: 70rpx;
	}

	.diy-navbar .item text {
		display: block;
		text-overflow: ellipsis;
		white-space: nowrap;
		width: 100%;
		overflow: hidden;
		line-height: 66rpx;
		font-size: 26rpx;
		text-align: center;
	}
</style>
